import PlayerView from "./PlayerView";
import { FaceType, ActionType, EventName } from "../../public/Config";
import GlobalEvent from "../../cfw/event/GlobalEvent";

const { ccclass, property } = cc._decorator;

@ccclass
export default class AddPlayer extends cc.Component {

    @property(cc.Prefab)
    player: cc.Prefab = null;

    @property
    offsetX: number = 0

    @property
    offsetY: number = 0;

    @property
    scale: number = 1;

    @property
    armIndex: number = 0;

    @property
    ignoreAdge: number = 0;

    @property({ type: cc.Enum(FaceType) })
    faceType: FaceType = FaceType.OPEN_SMILE;
    // @property
    // isShellOpen: number = 1;
    // private playerView: PlayerView = null;

    start() {
        let node = cc.instantiate(this.player)
        node.scale = this.scale;
        node.x = this.offsetX;
        node.y = this.offsetY;
        this.node.addChild(node)
        let comp: PlayerView = node.getComponent(PlayerView)
        // this.playerView = comp;
        comp.setArmIndex(this.armIndex)
        comp.setIgnoreAdge(this.ignoreAdge)
        this.setFaceType(this.faceType)
        // comp.setShellOpen(this.isShellOpen)
    }

    setFaceType(t: number) {
        // if (this.playerView) {
        // this.playerView.setFaceType(t)
        GlobalEvent.instance().emit(EventName.CHANGE_FACE_TYPE, t)
        // }
    }

    // setAction(type: ActionType, param?) {
    //     cc.log(" AddPlayer setAction 111")
    //     if (this.playerView){
    //         cc.log(" AddPlayer setAction ")
    //         this.playerView.setAction(type, param)
    //     }else{
    //         cc.log(' this.playerView is null ')
    //     }

    // }
    // update (dt) {}
}
